local WinScene = class("WinScene", cc.load("mvc").ViewBase)
WinScene.RESOURCE_FILENAME = "scene/WinScene.csb"
local mes = require("app.data.message")

function WinScene:onCreate()
    self:initData()
    self:initUI()
end

function WinScene:initData()
    if award then
        self._award = award
    end
end

function WinScene:initUI()
    local root = self:getResourceNode()
    root:setAnchorPoint(cc.p(0.5, 0.5))
    root:setPosition(win_size.width / 2, win_size.height / 2)

    -- 奖励植物卡
    local award_sprite = root:getChildByName("award_sprite")

    -- 奖励文本
    local award_text = root:getChildByName("award_text")

    -- 说明文本
    local introduction_text = root:getChildByName("introduction_text")
    introduction_text:ignoreContentAdaptWithSize(false)
    introduction_text:setContentSize(cc.size(220, 600))

    if self._award then
        local sf = cc.SpriteFrameCache:getInstance():getSpriteFrameByName(self._award)
        award_sprite:setSpriteFrame(sf)
        award_text:setString(mes[self._award]["name"])
        introduction_text:setString(mes[self._award]["introduction"])
    end

    -- 下一关按钮
    local next_btn = root:getChildByName("next_btn")
    next_btn:addTouchEventListener(
        function(sender, type)
            local scene = self:getApp():createScene("GameScene")
            cc.Director:getInstance():replaceScene(scene)
        end
    )

    -- 返回主菜单按钮
    local return_btn = root:getChildByName("return_btn")
    return_btn:addTouchEventListener(
        function(sender, type)
            local scene = self:getApp():createScene("MainScene")
            cc.Director:getInstance():replaceScene(scene)
        end
    )
end

return WinScene
